import models.*;

import org.junit.Test;

import play.test.Fixtures;
import play.test.UnitTest;

public class Nataly extends UnitTest {

	@Test
	public void followOrganizationCheck() {
		Fixtures.deleteAll();
		IdeaDeveloper dev = new IdeaDeveloper("nataly", "nataly", "nataly",
				"nataly.wadie@gmail.com", "4/3/1991", "nasr city");
		dev.save();
		IdeaDeveloper dev2 = new IdeaDeveloper("nataly1", "nataly1", "nataly1",
				"nataly.wadie@gmail.com", "4/3/1991", "nasr city");
		dev2.save();
		IdeaDeveloper dev3 = new IdeaDeveloper("nataly2", "nataly2", "nataly2",
				"nataly.wadie@gmail.com", "4/3/1991", "nasr city");
		dev3.save();
		OrganizationLead lead = OrganizationLead.create(dev3);
		lead.save();
		Organization org = Organization.create(dev3, "new Org", "new org",
				"public");
		org.save();
		Entities ent = org.addEntitiyReturn("new entity", dev3);
		ent.save();
		Tag tag = new Tag("new tag");
		tag.save();
		Topic topic = Topic.createTopicEnt("new topic",
				"new topic in new entity", ent.id, dev3.id);
		topic.save();
		Organization.followOrganization(dev, org);
		Organization.followOrganization(dev2, org);
		Entities.followEntity(dev, ent);
		Entities.followEntity(dev2, ent);
		Tag.followTag(dev, tag);
		Tag.followTag(dev2, tag);
		Topic.followTopic(dev, topic);
		Topic.followTopic(dev2, topic);
		assertEquals(1, dev.followedOrg.size());
		assertEquals(1, dev2.followedOrg.size());
		assertEquals(3, org.followed.size());
		assertEquals(1, dev.followedEnt.size());
		assertEquals(1, dev2.followedEnt.size());
		assertEquals(2, ent.followed.size());
		assertEquals(1, dev.followedTag.size());
		assertEquals(1, dev2.followedTag.size());
		assertEquals(2, tag.followed.size());
		assertEquals(1, dev.followedTop.size());
		assertEquals(1, dev2.followedTop.size());
		assertEquals(3, topic.followed.size());
		Organization.unfollowOrganization(dev, org);
		Entities.unfollowEntity(dev, ent);
		Tag.unfollowTag(dev, tag);
		Topic.unfollowTopic(dev, topic);
		assertEquals(0, dev.followedOrg.size());
		assertEquals(1, dev2.followedOrg.size());
		assertEquals(2, org.followed.size());
		assertEquals(0, dev.followedEnt.size());
		assertEquals(1, dev2.followedEnt.size());
		assertEquals(1, ent.followed.size());
		assertEquals(0, dev.followedTag.size());
		assertEquals(1, dev2.followedTag.size());
		assertEquals(1, tag.followed.size());
		assertEquals(0, dev.followedTop.size());
		assertEquals(1, dev2.followedTop.size());
		assertEquals(2, topic.followed.size());
	}

	@Test
	public void deleteOrganizationCheck() {
		IdeaDeveloper ideaDeveloper = new IdeaDeveloper("nataly wadie",
				"nataly", "nataly", "nataly.wadie@gmail.com", "1/1/2000",
				"nataly");
		ideaDeveloper.save();
		Organization organization = Organization.create(ideaDeveloper,
				"new organization", "new organization", "public");
		organization.save();
		Entities entity = organization.addEntitiyReturn("new entity",
				ideaDeveloper);
		entity.save();
		Topic topicInEntity = Topic.createTopicEnt("new topic in entity",
				"new topic in entity", entity.id, ideaDeveloper.id);
		topicInEntity.postATopic();
		topicInEntity.save();
		Idea ideaInEntity = Idea.createIdeaEntity("ideaInEntity",
				"idea in entity", ideaDeveloper.id, entity.id);
		ideaInEntity.postAnIdea();
		ideaInEntity.save();
		Topic topicInOrganization = Topic.createTopicOrg("new topic in org",
				"new topic in org", organization.id, ideaDeveloper.id);
		topicInOrganization.postATopic();
		topicInOrganization.save();
		Idea ideaInTopic = Idea.createIdeaTopic("idea in topic",
				"idea in topic", ideaDeveloper.id, topicInOrganization.id);
		ideaInTopic.postAnIdea();
		ideaInTopic.save();
		OrganizationLead organizationLead = organization.creator;
		assertEquals(2, ideaDeveloper.createdTopics.size());
		assertEquals(2, ideaDeveloper.createdIdeas.size());
		assertEquals(1, organization.creator.manages.size());
		assertEquals(1, organization.creator.createdOrgs.size());
		assertEquals(1, entity.managers.size());
		organization.delete2();
		assertEquals(0, organizationLead.createdOrgs.size());
		assertEquals(0, ideaDeveloper.createdTopics.size());
		assertEquals(0, ideaDeveloper.createdIdeas.size());
	}

}
